//
//  HomeBmapListCell.m
//  Jlcf_ios
//
//  Created by Ji on 2018/9/27.
//  Copyright © 2018 ski. All rights reserved.
//

#import "uXnlJqJLCFHomeBmapListCellqPDupe.h"
#import "uzZucYJLCFHomeBmapModelAwTcXU.h"
#import "zzknojJLCFListDetailViewControllerFwedjf.h"
#import "rmMqyfJLCFLoginAndRegisterControllerFbzYtj.h"


@interface HomeBmapListView : UIView

@property (nonatomic, strong) uzZucYJLCFHomeBmapModelAwTcXU *model;

- (instancetype)initWithFrame:(CGRect)frame;

- (void)reloadData;

@end

@interface HomeBmapListView ()

@property (nonatomic, strong) UIImageView *szXnJCbmapBgImgyxRdDG;

@property (nonatomic, strong) UIView *wDtvRJtimeBackViewCAflDN;

@property (nonatomic, strong) UILabel *hnRcVmtimeLabelncDSPi;
@property (nonatomic, strong) UILabel *LufDjKnameLabelRjatWG;

@property (nonatomic, strong) UILabel *DqlqILaprLabelIPueGU;
@property (nonatomic, strong) UILabel *SPNJwqaprDesLabelYEHzrm;

@property (nonatomic, strong) UILabel *zCFozurestLabelGrseuq;
@property (nonatomic, strong) UILabel *OShPwarestDesLabelVPTxiW;

@property (nonatomic, strong) UIView *MhOsdeprogressViewSXAiXa;
@property (nonatomic, strong) CAShapeLayer *ZLmcEJshapeLayerWDClkp;

@property (nonatomic, strong) UILabel *ATnLcEprecentLabelwLETIk;

@property (nonatomic, strong) UILabel *PrPdQjprecentDesLabelVgKULf;

@end

@implementation HomeBmapListView

- (instancetype)initWithFrame:(CGRect)frame
{
    
    if (self = [super initWithFrame:frame]) {
        
        if (!self.szXnJCbmapBgImgyxRdDG) {
            
            self.szXnJCbmapBgImgyxRdDG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
//            self.szXnJCbmapBgImgyxRdDG.image = [UIImage imageNamed:@"icon_home_newBg"];
            [self addSubview:self.szXnJCbmapBgImgyxRdDG];
        }
        
    }
    return self;
}

- (void)reloadData
{
    if (self.model) {
        if (!self.wDtvRJtimeBackViewCAflDN) {
            self.wDtvRJtimeBackViewCAflDN = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
            [self addSubview:self.wDtvRJtimeBackViewCAflDN];
            self.wDtvRJtimeBackViewCAflDN.backgroundColor = RGB(96, 112, 149);
            self.wDtvRJtimeBackViewCAflDN.left = 15;
            self.wDtvRJtimeBackViewCAflDN.top = 10;
            self.wDtvRJtimeBackViewCAflDN.layer.cornerRadius = 3;
            self.wDtvRJtimeBackViewCAflDN.layer.masksToBounds = YES;
        }
        
        if (!self.hnRcVmtimeLabelncDSPi) {
            self.hnRcVmtimeLabelncDSPi = [UILabel new];
            self.hnRcVmtimeLabelncDSPi.textColor = QTZ_White;
            self.hnRcVmtimeLabelncDSPi.font = FONT(10);
            [self addSubview:self.hnRcVmtimeLabelncDSPi];
        }
        
        if (self.hnRcVmtimeLabelncDSPi) {
            self.hnRcVmtimeLabelncDSPi.text = [NSString stringWithFormat:@"%@天", self.model.timeLimitDay];
            [self.hnRcVmtimeLabelncDSPi sizeToFit];
            self.hnRcVmtimeLabelncDSPi.centerX = self.wDtvRJtimeBackViewCAflDN.centerX;
            self.hnRcVmtimeLabelncDSPi.centerY = self.wDtvRJtimeBackViewCAflDN.centerY;
        }
        
        if (!self.LufDjKnameLabelRjatWG) {
            self.LufDjKnameLabelRjatWG = [UILabel new];
            self.LufDjKnameLabelRjatWG.textColor = QTZ_Gray51;
            self.LufDjKnameLabelRjatWG.font = FONT(10);
            [self addSubview:self.LufDjKnameLabelRjatWG];
        }
        if (self.LufDjKnameLabelRjatWG) {
            self.LufDjKnameLabelRjatWG.text = [NSString stringWithFormat:@"%@", self.model.name];
            [self.LufDjKnameLabelRjatWG sizeToFit];
            self.LufDjKnameLabelRjatWG.left = self.wDtvRJtimeBackViewCAflDN.right + 10;
            self.LufDjKnameLabelRjatWG.centerY = self.wDtvRJtimeBackViewCAflDN.centerY;
        }
        
        if (!self.DqlqILaprLabelIPueGU) {
            self.DqlqILaprLabelIPueGU = [UILabel new];
            self.DqlqILaprLabelIPueGU.textColor = Theme_Color;
            self.DqlqILaprLabelIPueGU.font = FONT(20);
            [self addSubview:self.DqlqILaprLabelIPueGU];
        }
        
        if (self.DqlqILaprLabelIPueGU) {
            if ([self.model.addApr isEqualToString:@"0"]) {
                self.DqlqILaprLabelIPueGU.text = [NSString stringWithFormat:@"%@%%", self.model.realApr];
            } else {
                NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%%+%@%%", self.model.realApr, self.model.addApr]];
                [attributeStr addAttribute:NSFontAttributeName value:FONT(9) range:NSMakeRange(0, attributeStr.length)];
                [attributeStr addAttribute:NSFontAttributeName value:FONT(16) range:NSMakeRange(0, self.model.realApr.length)];
                self.DqlqILaprLabelIPueGU.attributedText = attributeStr;
            }
            [self.DqlqILaprLabelIPueGU sizeToFit];
            self.DqlqILaprLabelIPueGU.centerX = 80;
            self.DqlqILaprLabelIPueGU.top = self.wDtvRJtimeBackViewCAflDN.bottom + 20;
        }
        
        if (!self.SPNJwqaprDesLabelYEHzrm) {
            self.SPNJwqaprDesLabelYEHzrm = [UILabel labelWithText:@"预期年化收益" textColor:QTZ_Gray102 font:FONT(6)];
            self.SPNJwqaprDesLabelYEHzrm.centerX = self.DqlqILaprLabelIPueGU.centerX;
            self.SPNJwqaprDesLabelYEHzrm.top = self.DqlqILaprLabelIPueGU.bottom + 2;
            [self addSubview:self.SPNJwqaprDesLabelYEHzrm];
        }
        
        if (!self.zCFozurestLabelGrseuq) {
            self.zCFozurestLabelGrseuq = [UILabel new];
            self.zCFozurestLabelGrseuq.textColor = QTZ_Gray51;
            self.zCFozurestLabelGrseuq.font = FONT(11);
            self.zCFozurestLabelGrseuq.textAlignment = NSTextAlignmentCenter;
            [self addSubview:self.zCFozurestLabelGrseuq];
        }

        if (self.zCFozurestLabelGrseuq) {
            self.zCFozurestLabelGrseuq.text = [NSString stringWithFormat:@"%@元", self.model.remmoney];
            [self.zCFozurestLabelGrseuq sizeToFit];
            self.zCFozurestLabelGrseuq.centerX = self.centerX;
            self.zCFozurestLabelGrseuq.bottom = self.DqlqILaprLabelIPueGU.bottom;
        }
        
        if (!self.OShPwarestDesLabelVPTxiW) {
            self.OShPwarestDesLabelVPTxiW = [UILabel labelWithText:@"剩余可投资金额" textColor:QTZ_Gray102 font:FONT(6)];
            self.OShPwarestDesLabelVPTxiW.centerX = self.zCFozurestLabelGrseuq.centerX;
            self.OShPwarestDesLabelVPTxiW.top = self.zCFozurestLabelGrseuq.bottom + 2;
            [self addSubview:self.OShPwarestDesLabelVPTxiW];
        }
        
        if (!self.MhOsdeprogressViewSXAiXa) {
            self.MhOsdeprogressViewSXAiXa = [[UIView alloc] init];
            self.MhOsdeprogressViewSXAiXa.frame = CGRectMake(0, 0, 72, 72);
            self.MhOsdeprogressViewSXAiXa.centerY = 50;
            self.MhOsdeprogressViewSXAiXa.right = self.szXnJCbmapBgImgyxRdDG.right - 25;
            
            [self addSubview:self.MhOsdeprogressViewSXAiXa];
            
            UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(36, 36) radius:32 startAngle:M_PI/2 endAngle:5 * M_PI/2 clockwise:YES];
            
            CAShapeLayer *bgLayer = [CAShapeLayer layer];
            bgLayer.fillColor = [UIColor clearColor].CGColor;
            bgLayer.lineWidth = 4.f;
            bgLayer.strokeColor = QTZ_Gray230.CGColor;
            bgLayer.strokeStart = 0;
            bgLayer.strokeEnd = 1;
            bgLayer.lineCap = kCALineCapRound;
            bgLayer.path = circlePath.CGPath;
            [self.MhOsdeprogressViewSXAiXa.layer addSublayer:bgLayer];
            
            _ZLmcEJshapeLayerWDClkp = [CAShapeLayer layer];
            _ZLmcEJshapeLayerWDClkp.fillColor = [UIColor clearColor].CGColor;
            _ZLmcEJshapeLayerWDClkp.lineWidth = 4.f;
            _ZLmcEJshapeLayerWDClkp.lineCap = kCALineCapRound;
            _ZLmcEJshapeLayerWDClkp.strokeColor = Theme_Color.CGColor;
            _ZLmcEJshapeLayerWDClkp.strokeStart = 0;
            _ZLmcEJshapeLayerWDClkp.strokeEnd = 0;
            _ZLmcEJshapeLayerWDClkp.path = circlePath.CGPath;
            [self.MhOsdeprogressViewSXAiXa.layer addSublayer:_ZLmcEJshapeLayerWDClkp];
        }
        
        double scales = [self.model.scales doubleValue];
        
        
        if (self.MhOsdeprogressViewSXAiXa) {
            _ZLmcEJshapeLayerWDClkp.strokeEnd = [self.model.scales doubleValue];
        }
        
        if (!self.ATnLcEprecentLabelwLETIk) {
            self.ATnLcEprecentLabelwLETIk = [UILabel new];
            self.ATnLcEprecentLabelwLETIk.textColor = Theme_Color;
            self.ATnLcEprecentLabelwLETIk.font = FONT(11);
            self.ATnLcEprecentLabelwLETIk.textAlignment = NSTextAlignmentCenter;
            [self.MhOsdeprogressViewSXAiXa addSubview:self.ATnLcEprecentLabelwLETIk];
        }
        if (self.ATnLcEprecentLabelwLETIk) {
            self.ATnLcEprecentLabelwLETIk.text = [NSString stringWithFormat:@"%.g%%", scales*100];;
            [self.ATnLcEprecentLabelwLETIk sizeToFit];
            self.ATnLcEprecentLabelwLETIk.centerX = 36;
            self.ATnLcEprecentLabelwLETIk.top = 20;
        }
        
        if (!self.PrPdQjprecentDesLabelVgKULf) {
            self.PrPdQjprecentDesLabelVgKULf = [UILabel labelWithText:@"投资进度" textColor:QTZ_Gray102 font:FONT(7)];
            self.PrPdQjprecentDesLabelVgKULf.centerX = self.ATnLcEprecentLabelwLETIk.centerX;
            self.PrPdQjprecentDesLabelVgKULf.top = self.ATnLcEprecentLabelwLETIk.bottom + 2;
            [self.MhOsdeprogressViewSXAiXa addSubview:self.PrPdQjprecentDesLabelVgKULf];
        }
        
        
    }
    
}

@end

@interface HomeBmapListCell ()

@property (nonatomic, strong) UIImageView *KxPjREattachImgQnJZLA;

@property (nonatomic, strong) UILabel *lHLQaCcategoryLabelrFFGMy;

@property (nonatomic, strong) UILabel *edHyphtipsLabelTVYPVW;

@property (nonatomic, strong) HomeBmapListView *LLOSDTleftViewRIIIyQ;

@property (nonatomic, strong) UIView *zSVkejgapViewFHHaZg;

@property (nonatomic, strong) HomeBmapListView *rightView;


@end

@implementation HomeBmapListCell

- (void)reloadData
{
    self.backgroundColor = QTZ_White;

    if (self.QVdfMwbmapArrWKXWGt) {
        
        if (!self.KxPjREattachImgQnJZLA) {
            self.KxPjREattachImgQnJZLA = [[UIImageView alloc] initWithFrame:CGRectMake(15, 12, 5, 15)];
            self.KxPjREattachImgQnJZLA.image = [UIImage imageNamed:@"icon_home_KxPjREattachImgQnJZLA"];
            self.KxPjREattachImgQnJZLA.backgroundColor = RGB(249, 205, 33);
            [self addSubview:self.KxPjREattachImgQnJZLA];
        }
        
        if (!self.lHLQaCcategoryLabelrFFGMy) {
            self.lHLQaCcategoryLabelrFFGMy = [UILabel labelWithText:@"快速投标" textColor:QTZ_Gray51 font:FONT(13)];
            self.lHLQaCcategoryLabelrFFGMy.centerY = self.KxPjREattachImgQnJZLA.centerY;
            self.lHLQaCcategoryLabelrFFGMy.left = self.KxPjREattachImgQnJZLA.right + 7;
            [self addSubview:self.lHLQaCcategoryLabelrFFGMy];
        }
        
        if (!self.edHyphtipsLabelTVYPVW) {
            self.edHyphtipsLabelTVYPVW = [UILabel labelWithText:@"安心存取，收益稳健" textColor:QTZ_Gray153 font:FONT(7)];
            self.edHyphtipsLabelTVYPVW.centerY = self.KxPjREattachImgQnJZLA.centerY;
            self.edHyphtipsLabelTVYPVW.left = self.lHLQaCcategoryLabelrFFGMy.right + 9;
            [self addSubview:self.edHyphtipsLabelTVYPVW];
        }
        
        if (!self.LLOSDTleftViewRIIIyQ) {
            self.LLOSDTleftViewRIIIyQ = [[HomeBmapListView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
            self.LLOSDTleftViewRIIIyQ.top = 39;
            self.LLOSDTleftViewRIIIyQ.left = 0;
            [self addSubview:self.LLOSDTleftViewRIIIyQ];
        }
        
        weakify(self);
        if (self.LLOSDTleftViewRIIIyQ) {
            self.LLOSDTleftViewRIIIyQ.model = [self.QVdfMwbmapArrWKXWGt safeObjectAtIndex:0];
            [self.LLOSDTleftViewRIIIyQ reloadData];
            [self.LLOSDTleftViewRIIIyQ bk_whenTapped:^{
                strongify(self);
                uzZucYJLCFHomeBmapModelAwTcXU *model = [self.QVdfMwbmapArrWKXWGt safeObjectAtIndex:0];
                [self toListDetail:model];
            }];
        }
        if (!self.zSVkejgapViewFHHaZg) {
            self.zSVkejgapViewFHHaZg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.5)];
            self.zSVkejgapViewFHHaZg.backgroundColor = LINECOLOR;
            self.zSVkejgapViewFHHaZg.top = self.LLOSDTleftViewRIIIyQ.bottom + 5;
            [self addSubview:self.zSVkejgapViewFHHaZg];
        }
        
        if (!self.rightView) {
            self.rightView = [[HomeBmapListView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
            self.rightView.top = self.LLOSDTleftViewRIIIyQ.bottom+10;
            self.rightView.left = 0;
            [self addSubview:self.rightView];
        }

        if (self.rightView) {
            self.rightView.model = [self.QVdfMwbmapArrWKXWGt safeObjectAtIndex:1];
            [self.rightView reloadData];
            [self.rightView bk_whenTapped:^{
                strongify(self);
                uzZucYJLCFHomeBmapModelAwTcXU *model = [self.QVdfMwbmapArrWKXWGt safeObjectAtIndex:1];
                [self toListDetail:model];
            }];
        }
        
    }
    
}

- (void)toListDetail:(uzZucYJLCFHomeBmapModelAwTcXU *)model {
    if ([JLCFRegisterService shareService].hasToken){
        zzknojJLCFListDetailViewControllerFwedjf *detailVC = [zzknojJLCFListDetailViewControllerFwedjf new];
        detailVC.bxiKZJproTitlehvcALF = model.name;
        detailVC.proId = model.id;
        [[[JinLiCaiFuApplicationEntrace shareEntrance] currentNavController] pushViewController:detailVC animated:YES];
    }else{
        rmMqyfJLCFLoginAndRegisterControllerFbzYtj *vc = [rmMqyfJLCFLoginAndRegisterControllerFbzYtj new];
        
        if (![[JinLiCaiFuApplicationEntrace shareEntrance] isContainVC:@"LoginAndRegisterController"]) {
            [[[JinLiCaiFuApplicationEntrace shareEntrance] currentNavController] pushViewController:vc animated:YES];
            [vc showNotice:@"请登陆或注册"];
        }
    }
}


@end
